package com.zws.cucumber.expander;

import java.util.stream.Stream;

public class ZwsStrOption {

    public static final ZwsStrOption DefaultOption = new ZwsStrOption();

    private boolean isDebug = false;
    private boolean isPrettyPrintJson = false;

    public boolean isDebug() {
        return isDebug;
    }

    public boolean isPrettyPrintJson() {
        return isPrettyPrintJson;
    }

    public static ZwsStrOption parse(String optionString) {
        if (!optionString.startsWith(">") || !optionString.endsWith("< ")) {
            throw new IllegalArgumentException("ZwsStrOption should startWith '>' and endWith '< ', but was " + optionString);
        }
        System.out.println("option string: " + optionString);
        optionString = optionString.substring(1, optionString.length() - 2);
        ZwsStrOption options = new ZwsStrOption();
        Stream.of(optionString.split(","))
                .forEach(s -> {
                    s = s.trim();
                    switch (s) {
                        case "d": options.isDebug = true; break;
                        case "p": options.isPrettyPrintJson = true; break;
                        default: throw new IllegalArgumentException();
                    }
                });
        return options;
    }
}
